package cn.xiaopengstack.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jiangyangang
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ModelNameVal{
    private String displayName;
    private String modelRequireName;

    public static List<ModelNameVal> init(List<String> models) {

        if (CollectionUtils.isEmpty(models)) {
            throw new RuntimeException("模型配置有误，未指定当前模型名称!");
        }

        return models.stream().map(originModelStr -> {
            ModelNameVal modelNameVal = new ModelNameVal();
            String[] split = originModelStr.split("->");
            if (split.length == 2) {
                modelNameVal.setDisplayName(split[0]);
                modelNameVal.setModelRequireName(split[1]);
            } else {
                modelNameVal.setDisplayName(split[0]);
                modelNameVal.setModelRequireName(split[0]);
            }

            return modelNameVal;
        }).collect(Collectors.toList());
    }
}